import requests from "@/api/requests";

// //登录
export const reqUserLogin = (data) =>
  requests("/auth/login", {
    method: "post",
    headers: {
      "Content-Type": "application/json", // 声明 JSON 格式
    },
    data: JSON.stringify(data), // 数据需转为 JSON 字符串
  });
// 登录
// export const reqUserLogin = (data) => requests({
//   url: "/auth/login",
//   method: "post",
//   headers: { "Content-Type": "application/json" },
//   data: data  // Axios 自动转换 JSON
// });

//获取验证码

export const reqGetCode = () => requests.get("/auth/captcha");

//验证邮箱是否存在
export const reqCheckEmail = (data) =>
  requests.get("/auth/checkEmail", { params: { email: data } });

//注册

export const reqUserRegister = (data) =>
  requests("/auth/register", {
    method: "post",
    headers: {
      "Content-Type": "application/json", // 声明 JSON 格式
    },
    data: JSON.stringify(data), // 数据需转为 JSON 字符串
  });

//登出
export const reqUserLogout = () => requests.post("/auth/logout");

//ai接口
export const reqAi = (data) =>
  requests("/ai/chat", {
    method: "post",
    headers: {
      "Content-Type": "application/json", // 声明 JSON 格式
    },
    // responseType: "stream", // 关键配置：声明流式响应
    data, // 数据需转为 JSON 字符串
  });

// 获取用户信息
export const reqGetUserInfo = () => requests.get("/user/profile");

// 修改用户信息
export const reqUpdateUserInfo = (data) =>
  requests("/user/profile", {
    method: "put",
    headers: {
      "Content-Type": "application/json",
    },
    data,
  }); //post传body参数，form-data参数也是post

//获取首页轮播图
export const reqGetHomepage = () => requests.get("/homepage/random");

// http://localhost:8081/api/user/comp/rank
//获取热点比赛
export const reqGetHotCompetition = (data) =>
  requests.get("/user/comp/rank", { params: { category: data } });

//获取全部比赛
export const reqGetAllCompetition = (data) =>
  requests.get("/user/comp/page", { params: data }); //get传params

// http://localhost:8080/api/user/comp
//添加比赛
export const reqAddCompetition = (data) => requests.post("/user/comp", data);

// /api/user/comp
//修改比赛
export const reqUpdateCompetition = (data) => requests.put("/user/comp", data);

// http://localhost:8080/api/user/comp
//删除比赛
export const reqDeleteCompetition = (ids) =>
  requests.delete("/user/comp", {
    headers: {
      "Content-Type": "multipart/form-data",
    },
    data: ids,
  });

//获取比赛详情
export const reqGetCompetitionDetail = (id) => requests.get(`/user/comp/${id}`);

//获取比赛评论
// http://localhost:8081/api/competitions/{competitionId}/comments
export const reqGetCompetitionComment = (competitionId) =>
  requests.get(`/competitions/${competitionId}/comments`);

// http://localhost:8081/api/competitions/{competitionId}/comments

// 1. 新增：添加评论接口
export const reqAddCompetitionComment = (competitionId, data) =>
  requests.post(`/competitions/${competitionId}/comments`, data);
// export const reqAddCompetitionComment = (competitionId, data) =>
//   requests.get(`/competitions/${competitionId}/comments`, { params: data });

// http://localhost:8081/api/competitions/{competitionId}/comments/like/{id}
// 2. 新增：点赞评论接口
export const reqAddCommentLike = (competitionId, commentId) =>
  requests.post(`/competitions/${competitionId}/comments/like/${commentId}`);

//删除评论
// http://localhost:8081/api/competitions/{competitionId}/comments/{id}
export const reqDeleteComment = (competitionId, id) =>
  requests.delete(`/competitions/${competitionId}/comments/${id}`);

// 点击头像进入主页
// http://localhost:8081/api/competitions/{competitionId}/comments/user/userProfile/{userId}
export const reqUserProfile = (data) =>
  requests.get(
    `/competitions/${data.competitionId}/comments/user/userProfile/${data.userId}`
  );

//私信接口*************************************************************/

// http://localhost:8081/api/message/online/users
// 1. 新增：查询在线用户接口
export const reqOnlineUsers = () => requests.get("/message/online/users");

// http://localhost:8081/api/message/conversation/search
// 1. 新增：查询会话接口
export const reqSearchConversation = (data) =>
  requests.get(`/message/conversation/search`, { params: { username: data } });

// http://localhost:8082/api/message/send
export const reqSendMessage = (data) => requests.post(`/message/send`, data);

// http://localhost:8082/api/message/conversations
export const reqGetConversations = () => requests.get(`/message/conversations`);

// http://localhost:8082/api/message/history
export const reqGetHistory = (data) =>
  requests.get(`/message/history`, { params: data });

//http://localhost:8082/api/message/read/{messageId}
export const reqReadMessage = (messageId) =>
  requests.put(`/message/read/${messageId}`);

// http://localhost:8082/api/message/{messageId}
export const reqDeleteMessage = (messageId) =>
  requests.delete(`/message/${messageId}`);

// http://localhost:8082/api/message/unread/count
export const reqGetUnreadCount = () => requests.get(`/message/unread/count`);

// http://localhost:8082/api/message/conversation/read
export const reqReadConversation = (data) =>
  requests.put(`/message/conversation/read`, { params: data });
